 # Copyright (C) 2000, 2001, 2013 Gregory Trubetskoy
 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Apache Software Foundation
 #
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
 #  You may obtain a copy of the License at
 #
 #      http://www.apache.org/licenses/LICENSE-2.0
 #
 #  Unless required by applicable law or agreed to in writing, software
 #  distributed under the License is distributed on an "AS IS" BASIS,
 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 #
 # Originally developed by Gregory Trubetskoy.
 #

CC=gcc
AR=ar
APXS=/usr/sbin/apxs
MKDEP=@MKDEP@

# requires flex 2.5.31 for reentrant support
LEX=/usr/bin/flex
INCLUDES=-I/home/cheungssh/soft/mod_python-3.4.1/src/include
CPPFLAGS=-I/usr/include/python2.6 -D_GNU_SOURCE -DNDEBUG -D_GNU_SOURCE
CFLAGS=
LDLIBS=-lpython2.6 -lpthread -ldl  -lutil
LDFLAGS=-L/usr/lib64 -L/usr/lib64/python2.6/config
srcdir=.

SRCS=	mod_python.c _apachemodule.c requestobject.c tableobject.c util.c \
		serverobject.c connobject.c filterobject.c hlist.c \
		hlistobject.c finfoobject.c version.c \
		include/_apachemodule.h  include/filterobject.h  include/hlist.h \
		include/mod_python.h  include/psp_flex.h include/psp_parser.h  \
		include/requestobject.h include/tableobject.h include/connobject.h \
		include/finfoobject.h include/hlistobject.h include/mp_version.h \
		include/_pspmodule.h  include/psp_string.h  include/serverobject.h \
		include/util.h

.PHONY: version

all:	dso

psp_parser.c: psp_parser.l
	@rm -f psp_parser.c
	$(LEX) -R -opsp_parser.c --header-file=include/psp_flex.h psp_parser.l

dso:	mod_python.so

mod_python.so: $(SRCS)  
	@echo
	@echo 'Building mod_python.so.'
	@echo
	$(APXS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $(SRCS) $(LDFLAGS) $(LDLIBS) 
	@rm -f mod_python.so
	@ln -s .libs/mod_python.so mod_python.so
clean:
	rm -rf $(OBJS) version.c core libpython.a mod_python.so *~ .libs *.o *.slo *.lo *.la

distclean: clean
	rm -f Makefile .depend

version.c:
	@MP_GIT_SHA=$$(git describe --always); \
	echo > version.c ; \
	echo "/* THIS FILE IS AUTO-GENERATED BY Makefile */" >> version.c ; \
	echo "#include \"mp_version.h\"" >> version.c ; \
	echo "const char * const mp_git_sha = \"$${MP_GIT_SHA}\";" >> version.c ; \
	echo "const int mp_version_major = MP_VERSION_MAJOR;" >> version.c ; \
	echo "const int mp_version_minor = MP_VERSION_MINOR;" >> version.c ; \
	echo "const int mp_version_patch = MP_VERSION_PATCH;" >> version.c ; \
	echo "const char * const mp_version_string = MP_VERSION_STRING(MP_VERSION_MAJOR,MP_VERSION_MINOR,MP_VERSION_PATCH) \"-$${MP_GIT_SHA}\";" >> version.c ; \
	echo "const char * const mp_version_component = \"mod_python/\" MP_VERSION_STRING(MP_VERSION_MAJOR,MP_VERSION_MINOR,MP_VERSION_PATCH) \"-$${MP_GIT_SHA}\";" >> version.c

#	echo "const char * const mp_version_component = \"mod_python/\" #MP_VERSION_MAJOR \".\" #MP_VERSION_MINOR \".\" #MP_VERSION_PATCH \"-$${MP_GIT_SHA}\";" >> version.c

# this is a hack to help avoid a gcc/solaris problem
# python uses assert() which needs _eprintf(). See 
# SOLARIS_HACKS above
_eprintf.o:
	ar -x `gcc -print-libgcc-file-name` _eprintf.o
_floatdidf.o:
	ar -x `gcc -print-libgcc-file-name` _floatdidf.o
_muldi3.o:
	ar -x `gcc -print-libgcc-file-name` _muldi3.o

# DO NOT DELETE THIS LINE
